/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.examat.web.utils;

import java.util.Map;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

public class Sesiones 
{
    public static void set(String name, Object value)
    {
        FacesContext fc = FacesContext.getCurrentInstance();
        HttpSession sc = (HttpSession)fc.getExternalContext().getSession(true);
        sc.setAttribute(name, value);
    }
    
    public static Object get(String name)
    {
        FacesContext fc = FacesContext.getCurrentInstance();
        Map<String, Object> map = fc.getExternalContext().getSessionMap();
        return map.get(name);
    }
    
    public static void destroySession()
    {
        FacesContext fc = FacesContext.getCurrentInstance();
        HttpSession sc = (HttpSession)fc.getExternalContext().getSession(false);
        sc.invalidate();
    }
    
    public static boolean checkLogin()
    {
        FacesContext fc = FacesContext.getCurrentInstance();
        Map<String, Object> map = fc.getExternalContext().getSessionMap();
        
        return map.get("user_name")!=null && map.get("user_type").equals("profesor");
    }
}
